<template>
  <div class="side_nav_box" ref="sideRef">
    <div class="side_header">
      <div class="web_title fw flex align_items_ctr jc_ctr">
        <img src="@/assets/imgs/web_logo.png" alt="">
        <div class="web_title_txt" v-if="!isCollapse">
          智读科研文献助手
        </div>
      </div>
    </div>
    <el-menu :default-active="defaultActive" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
      :collapse="isCollapse" background-color="transparent" active-text-color="#6d69dc" @select="selectMenuClick">
      <!-- <el-submenu index="/workstation">
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">工作台</span>
        </template>
<el-menu-item index="/workstation/record">使用记录</el-menu-item>
</el-submenu>
<el-menu-item index="/">
  <i class="el-icon-s-home"></i>
  <span slot="title">首页</span>
</el-menu-item>
<el-menu-item index="/resource">
  <i class="el-icon-document"></i>
  <span slot="title">资源</span>
</el-menu-item> -->
      <el-submenu index="/literatureManage">
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">文献管理</span>
        </template>
        <el-menu-item index="/library">我的素材库</el-menu-item>
        <el-menu-item index="ywgj">引文工具</el-menu-item>
        <el-menu-item index="wxzs">文献综述</el-menu-item>
      </el-submenu>
      <!-- <el-menu-item index="/wxyd">
        <i class="el-icon-document"></i>
        <span slot="title">AI解读</span>
      </el-menu-item> -->
    </el-menu>
    <div class="close_box flex pointer" @click="closeClick">
      <i :class="`el-icon-arrow-${isCollapse ? 'right' : 'left'}`"></i>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      isCollapse: false,
      defaultActive: '/'
    }
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath);
      if (this.$route.path !== key) {
        this.$router.push(key)
      }
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath);
      if (this.$route.path !== key) {
        this.$router.push(key)
      }
    },
    selectMenuClick (index, indexPath) {
      console.log(index, indexPath, 7222);
      if (index.indexOf('/') === 0) {
        this.$router.push(index)
      } else {
        if (index === 'ywgj') { }
        if (index === 'wxzs') { }
      }
    },
    getWidth () {
      return this.isCollapse ? 64 : 300
    },
    closeClick () {
      this.isCollapse = !this.isCollapse
      const side = this.$refs.sideRef;
      const handle = () => {
        const w = this.getWidth();
        console.log(w, 'width after transition');
        this.$emit('closeClick', w);
        side.removeEventListener('transitionend', handle);
      };
      side.addEventListener('transitionend', handle);
    }
  },
  watch: {
    '$route.path' (n, o) {
      this.defaultActive = n
    }
  }
}
</script>
<style lang="less" scoped>
.side_nav_box {
  position: relative;
  height: 100vh;
  // background: var(--bgcThemeColor);
  background: linear-gradient(to right top, #fff, var(--bgcThemeColor), #fff);
  border-right: 1px solid #ccc;

  .side_header {
    .web_title {
      height: 64px;

      >img {
        width: 28px;
        height: 28px;
      }

      .web_title_txt {
        font-size: 16px;
        margin-left: 10px;
      }
    }
  }

  /deep/.el-menu {
    // padding: 0 20px;
    border: 0;
  }

  /deep/.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 300px;
    min-height: 400px;
  }

  /deep/.el-menu-item.is-active {
    background: var(--lightThemeColor) !important;
  }

  /deep/.el-menu-item {
    // color: #fff;
    border-radius: 10px;
    // padding: 0 !important;

    i {
      // color: #fff;
    }

    &:hover {
      background: rgba(123, 118, 247, .1) !important;
    }
  }

  /deep/.el-tooltip {
    // padding: 0 !important;
  }

  /deep/.el-submenu__title {
    // padding: 0 !important;
  }

  .close_box {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateX(100%);
    width: 16px;
    height: 34px;
    background: var(--bgcThemeColor);
    z-index: 9999;
    border-radius: 0 6px 6px 0;

    >i {
      margin: auto;
      // color: #fff;
    }
  }
}
</style>